package com.zhilingshenghuo.app.zhly.view.widget;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zhilingshenghuo.app.zhly.R;
import com.zhilingshenghuo.app.zhly.entity.GetScoreListResponse;
import com.zhilingshenghuo.app.zhly.view.adapter.ScoreRecordAdapter;

import java.util.ArrayList;

public abstract class DeatilPopwindow {

    private PopupWindow popupWindow;
    private Activity context;
    //未锁定金币列表
    private ArrayList<GetScoreListResponse.ListBean.DataBean> mGoldList;

    //锁定金币列表
    private ArrayList<GetScoreListResponse.ListBean.DataBean> mLockGoldList;

    /**
     * 构造函数
     *
     * @param context
     */
    public DeatilPopwindow(Activity context,ArrayList<GetScoreListResponse.ListBean.DataBean> mGoldList,ArrayList<GetScoreListResponse.ListBean.DataBean> mLockGoldList) {
        this.context = context;
        this.mGoldList = mGoldList;
        this.mLockGoldList = mLockGoldList;
    }

    /**
     * 显示警示框
     */
    public void show() {
        View popView = View.inflate(context, R.layout.pop_deatil, null);
        popupWindow = new PopupWindow(context);
        popupWindow.setAnimationStyle(R.style.popWindow_animation);//设置动画
        popupWindow.setOutsideTouchable(false);
        popupWindow.setBackgroundDrawable(null);
        int width = context.getWindowManager().getDefaultDisplay().getWidth();
        popupWindow.setWidth(width);
        int height = context.getWindowManager().getDefaultDisplay().getHeight();
        popupWindow.setHeight(height*3/5);
        popupWindow.setFocusable(true);
        popupWindow.setContentView(popView);
        popupWindow.showAtLocation(context.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
        //关闭
        popView.findViewById(R.id.ivClose).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                onDisMiss();
            }
        });

        RelativeLayout rlLeft = popView.findViewById(R.id.rlLeft);
        RelativeLayout rlRight = popView.findViewById(R.id.rlRight);
        RecyclerView recyclerView = popView.findViewById(R.id.recyclerView);

        ScoreRecordAdapter goldAdapter = new ScoreRecordAdapter();
        goldAdapter.setNewInstance(mGoldList);
        recyclerView.setLayoutManager(new LinearLayoutManager(context,RecyclerView.VERTICAL,false));
        recyclerView.setAdapter(goldAdapter);

        ScoreRecordAdapter lockGoldAdapter = new ScoreRecordAdapter();
        lockGoldAdapter.setNewInstance(mLockGoldList);
        recyclerView.setLayoutManager(new LinearLayoutManager(context,RecyclerView.VERTICAL,false));


        rlLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rlLeft.setBackgroundResource(R.drawable.shape_bg_game_record_top_select);
                rlRight.setBackgroundResource(R.drawable.shape_bg_game_record_top);
                recyclerView.setAdapter(goldAdapter);
            }
        });

        rlRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rlRight.setBackgroundResource(R.drawable.shape_bg_game_record_top_select);
                rlLeft.setBackgroundResource(R.drawable.shape_bg_game_record_top);
                recyclerView.setAdapter(lockGoldAdapter);
            }
        });
    }


    /**
     * 消失
     */
    public abstract void onDisMiss();
}
